package lt.kraujutis.vilius.android.listallavailablesensors;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListAllAvailableSensorsActivity extends ListActivity {
	List<Sensor> sensors;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		SensorManager mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
		sensors = mSensorManager.getSensorList(Sensor.TYPE_ALL);

		List<String> sensorListStrings = new ArrayList<String>();

		for (Sensor sensor : sensors) {
			sensorListStrings.add(sensor.getName());
		}

		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item,
				sensorListStrings));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {

		super.onListItemClick(l, v, position, id);
		Sensor sensor = sensors.get(position);

		int type = sensor.getType();

		Intent intent = new Intent(this, SensorDetailsActivity.class);
		intent.putExtra("sensorType", type);
		startActivity(intent);
	}
}
